package cn.keniykey.mc.viewlibrary.container.api;

import javax.annotation.Nullable;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import cn.keniykey.mc.viewlibrary.ViewLibraryMain;
import cn.keniykey.mc.viewlibrary.packet.api.PacketWindowDataDispatch;

public class ContainerAnvil extends Container {
	
	public static interface IContainerAnvilItemNameHandler{
		public void onAnvilItemNameResponse(Player player,ContainerAnvil anvil,String str);
	}
	
	private IContainerAnvilItemNameHandler handler_itemname;
	
	protected ContainerAnvil(EContainerType type) {
		super(type);
	}
	public ContainerAnvil() {
		super(EContainerType.ANVIL);
	}
	
	public void setCostLevel(Player player,int level) {
		Bukkit.getScheduler().runTaskAsynchronously(ViewLibraryMain.getPlugin(), () -> {
			new PacketWindowDataDispatch(0, level).sendPacket(player);
		});
	}
	@Override
	public void setItemStack(int slot, ItemStack item, boolean display_packet) {
		if(slot == 0) {
			this.setForgingItemStack(item);
			return;
		}
		super.setItemStack(slot, item, display_packet);
	}
	public void setForgingItemStack(@Nullable ItemStack item) {
		super.setItemStack(2, null, true);
		super.setItemStack(0, item, true);
	}
	@Nullable
	public IContainerAnvilItemNameHandler getContainerAnvilItemNameHandler(){
		return this.handler_itemname;
	}
	public void setContainerAnvilItemNameHandler(@Nullable IContainerAnvilItemNameHandler handler) {
		this.handler_itemname = handler;
	}
}